<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="st-body">
    <div class="layui-fluid">
        <div class="st-h15"></div>
        <form class="layui-form" action="/strongadmin/webconfig/save/config">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">基本配置</li>
                    <!--<li class="">阿里云上传配置</li>-->
                    <!--<li>产品配置</li>-->
                </ul>
                <div class="layui-tab-content">
                    <!--基本设置-->
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站名称</label>
                            <div class="layui-input-block">
                                <input type="text" th:value="${configs.web_name}" name="web_name" autocomplete="off" placeholder="" class="layui-input">
                                <div class="layui-word-aux st-form-tip">网站内部标题使用</div>
                            </div>
                        </div>

                    </div>
                    <!--注册配置-->
                    <!--产品配置-->
                    <!--<div class="layui-tab-item">
                        <div class="layui-form-item">
                            <label class="layui-form-label">文件目录</label>
                            <div class="layui-input-block">
                                <input type="text" th:value="${configs.aliyun_file}" name="aliyun_file" autocomplete="off" placeholder="" class="layui-input">
                                <div class="layui-word-aux st-form-tip">books</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">bucketName</label>
                            <div class="layui-input-block">
                                <input type="text" th:value="${configs.aliyun_bucket_name}" name="aliyun_bucket_name" autocomplete="off" placeholder="" class="layui-input">
                                <div class="layui-word-aux st-form-tip">meiguosgo</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">endPoint</label>
                            <div class="layui-input-block">
                                <input type="text" th:value="${configs.aliyun_end_point}" name="aliyun_end_point" value="SGO, Cross border E-commerce，E-commerce website" autocomplete="off" placeholder="" class="layui-input">
                                <div class="layui-word-aux st-form-tip">oss-us-west-1.aliyuncs.com</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">keyId</label>
                            <div class="layui-input-block">
                                <input type="text" th:value="${configs.aliyun_access_key_id}" name="aliyun_access_key_id" value="SGO, Cross border E-commerce，E-commerce website" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">KeySecret</label>
                            <div class="layui-input-block">
                                <input type="text" th:value="${configs.aliyun_access_key_secret}" name="aliyun_access_key_secret" value="" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                        </div>
                    </div>-->
                </div>
            </div>
            <div class="layui-form-item st-form-submit-btn">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="ST-SUBMIT">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    !function () {
        //普通图片上传
        var uploadInst = layui.upload.render({
            elem: '#test1'
            , url: '/upload/image' //改成您自己的上传接口
            ,headers: {"authorization": token}
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code != 0) {
                    return layer.msg('上传失败');
                }
                layer.msg('上传成功');
                $(":input[name=web_logo]").val(res.data);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    }();
</script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;

    !function () {
        //监听提交
        layui.form.on('submit(ST-SUBMIT)', function (data) {
            //console.log(data)
            CoreUtil.sendPut("/webConfig/update", data.field, function (res) {
                layer.alert(res.msg);
                CoreUtil.sendPost("/webConfig/clearCache", null, function (res) {

                });
            });

            //layer.alert(JSON.stringify(data.field), {
            //    title: '最终的提交信息'
            //});
            return false;
        });
        //清缓存
        $("#clearcache").click(function () {
            CoreUtil.sendPost("/webConfig/clearCache", null, function (res) {
                layer.alert(res.msg);
            });
        });
        //测试邮件
        $("#sendReceiveMailTest").click(function () {
            var addr = $("#receiveMailTest").val();
            CoreUtil.sendPost("/webConfig/sendReceiveMailTest", {
                addr: addr
                , mailHost: $("input[name=MAIL_HOST]").val()
                , mailEncryption: $("select[name=MAIL_ENCRYPTION]").val()
                , mailPort: $("input[name=MAIL_PORT]").val()
                , mailUsername: $("input[name=MAIL_USERNAME]").val()
                , mailPassword: $("input[name=MAIL_PASSWORD]").val()
            }, function (res) {
                layer.alert(res.msg);
            });
        });
    }();
</script>
